/**
 * Created by 123 on 2016/10/10.
 */
import com.sun.imageio.plugins.bmp.BMPImageReader;
import com.sun.javafx.geom.AreaOp;

import javax.imageio.*;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.io.*;
import java.awt.Rectangle;
import java.util.Iterator;
public class ImageProcess {
    public static void cutImg(String ImgPath,float xPercent1,float yPercent1,float xPercent2,float yPercent2){
        String format=ImgPath.substring(ImgPath.length()-3,ImgPath.length());
        File img=new File(ImgPath);
        File imgModified=new File("Cut-"+ImgPath);
        Iterator readers = ImageIO.getImageReadersByFormatName(format);
        ImageReader imgReader=(ImageReader)readers.next();
        Iterator writers = ImageIO.getImageWritersByFormatName(format);
        ImageWriter imgWriter=(ImageWriter)writers.next();
        try{
            if(!imgModified.exists()){
                imgModified.createNewFile();
            }
            ImageInputStream imgIStream = ImageIO.createImageInputStream(img);
            imgReader.setInput(imgIStream);
            ImageOutputStream imgOStream = ImageIO.createImageOutputStream(imgModified);
            imgWriter.setOutput(imgOStream);
            BufferedImage imgData = imgReader.read(0);
            int originW = imgData.getWidth();
            int originH = imgData.getHeight();
            int modifiedWStart = Math.round(originW * xPercent1);
            int modifiedWEnd = Math.round(originW * xPercent2);
            int modifiedHStart = Math.round(originH * yPercent1);
            int modifiedHEnd=Math.round(originH * yPercent2);
            int modifiedW=Math.round((float)originW*(xPercent2-xPercent1));
            int modifiedH=Math.round((float)originH*(yPercent2-yPercent1));
            int[] pixelArray=new int[imgData.getHeight()*imgData.getWidth()];
            int[] modifiedPixelArray=new int[modifiedW*modifiedH];
            pixelArray=imgData.getRGB(0,0,originW,originH,pixelArray,0,originW);
            if(xPercent1>1||xPercent1<0||xPercent2>1||xPercent2<0||yPercent1>1||yPercent1<0||yPercent2>1||yPercent2<0){
                throw new Exception("Invalid Cutting Percentage");
            }
            else if((xPercent2<xPercent1)||(yPercent2<yPercent1)){
                throw new Exception("percent2 must greater than percent1!");
            }
            int count=0;
            int mX=0;
            for(int oY=modifiedHStart;oY<modifiedHEnd;oY++){
                for(int oX=modifiedWStart;oX<modifiedWEnd;oX++){
                    count=count>modifiedH*modifiedW-1?modifiedH*modifiedW-1:count;
                    modifiedPixelArray[count]=pixelArray[oY*originW+oX];
                    count++;
                }
            }
            BufferedImage modifiedData=new BufferedImage(modifiedW,modifiedH,imgData.getType());
            modifiedData.setRGB(0,0,modifiedW,modifiedH,modifiedPixelArray,0,modifiedW);
            imgWriter.write(modifiedData);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    /*public static void shrinkImg(String ImgPath,float scaleX,float scaleY){
        String format=ImgPath.substring(ImgPath.length()-3,ImgPath.length());
        File img=new File(ImgPath);
        File imgModified=new File("Mod-1-"+ImgPath);
        Iterator readers = ImageIO.getImageReadersByFormatName(format);
        ImageReader imgReader=(ImageReader)readers.next();
        Iterator writers = ImageIO.getImageWritersByFormatName(format);
        ImageWriter imgWriter=(ImageWriter)writers.next();
        try{
            if(scaleX>1||scaleY>1){
                throw new RuntimeException("Invalid Scale Input");
            }
            if(!imgModified.exists()){
                imgModified.createNewFile();
            }
            ImageInputStream imgIStream= ImageIO.createImageInputStream(img);
            imgReader.setInput(imgIStream);
            ImageOutputStream imgOStream=ImageIO.createImageOutputStream(imgModified);
            imgWriter.setOutput(imgOStream);
            BufferedImage imgData=imgReader.read(0);
            double sampleRateX=1/scaleX;
            double sampleRateY=1/scaleY;
            int originW=imgData.getWidth();
            int originH=imgData.getHeight();
            int modifiedW=Math.round(originW*scaleX);
            int modifiedH=Math.round(originH*scaleY);
            int[] pixelArray=new int[imgData.getHeight()*imgData.getWidth()];
            int[] outputPixelArray=new int[modifiedW*modifiedH];
            pixelArray=imgData.getRGB(0,0,originW,originH,pixelArray,0,originW);
            ColorModel color=ColorModel.getRGBdefault();
            double delta=(1+(sampleRateX-Math.floor(sampleRateX))/Math.floor(sampleRateX))*(1+(sampleRateY-Math.floor(sampleRateY))/Math.floor(sampleRateY));
            for(int mY=0;mY<modifiedH;mY++){
                for(int mX=0;mX<modifiedW;mX++){
                    int[] argb={0,0,0,0};
                    for(int oY=0;oY<sampleRateY;oY++){
                        for(int oX=0;oX<sampleRateX;oX++){
                            int currentPixel=(int)(mY*sampleRateY+oY)*originW+(int)(mX*sampleRateX+oX);
                            if(currentPixel>=originH*originW-1){
                                currentPixel=originH*originW-1;
                            }
                            argb[0]+=color.getAlpha(pixelArray[currentPixel])*delta;
                            argb[1]+=color.getRed(pixelArray[currentPixel])*delta;
                            argb[2]+=color.getGreen(pixelArray[currentPixel])*delta;
                            argb[3]+=color.getBlue(pixelArray[currentPixel])*delta;
                        }
                    }
                    for(int i=0;i<4;i++){
                        argb[i]=(int)(argb[i]/(1/scaleX*1/scaleY));
                        argb[i]<<=(3-i)*8;
                    }
                    outputPixelArray[mY*modifiedW+mX]=argb[0]|argb[1]|argb[2]|argb[3];
                }
            }
            BufferedImage modifiedData=new BufferedImage(modifiedW,modifiedH,imgData.getType());
            modifiedData.setRGB(0,0,modifiedW,modifiedH,outputPixelArray,0,modifiedW);
            imgWriter.write(modifiedData);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static void shrinkImg2(String ImgPath,float scaleX,float scaleY){
        String format=ImgPath.substring(ImgPath.length()-3,ImgPath.length());
        File img=new File(ImgPath);
        File imgModified=new File("Mod-2-"+ImgPath);
        Iterator readers = ImageIO.getImageReadersByFormatName(format);
        ImageReader imgReader=(ImageReader)readers.next();
        Iterator writers = ImageIO.getImageWritersByFormatName(format);
        ImageWriter imgWriter=(ImageWriter)writers.next();
        try {
            if (scaleX > 1 || scaleY > 1) {
                throw new RuntimeException("Invalid Scale Input");
            }
            if (!imgModified.exists()) {
                imgModified.createNewFile();
            }
            ImageInputStream imgIStream = ImageIO.createImageInputStream(img);
            imgReader.setInput(imgIStream);
            ImageOutputStream imgOStream = ImageIO.createImageOutputStream(imgModified);
            imgWriter.setOutput(imgOStream);
            BufferedImage imgData = imgReader.read(0);
            int originW=imgData.getWidth();
            int originH=imgData.getHeight();
            int modifiedW=Math.round(originW*scaleX);
            int modifiedH=Math.round(originH*scaleY);
            int[] pixelArray=new int[imgData.getHeight()*imgData.getWidth()];
            int[] outputPixelArray=new int[modifiedW*modifiedH];
            double sampleRateX=1d/scaleX;
            double sampleRateY=1d/scaleY;
            pixelArray=imgData.getRGB(0,0,originW,originH,pixelArray,0,originW);
            for(double y=0;y<modifiedH;y++){
                for (double x=0;x<modifiedW;x++){
                    int index=(int)((y*sampleRateY)*originW+(x*sampleRateX));
                    if((x*sampleRateX)>originW){
                        index=(int)(((y)*sampleRateY)*originW+originW-1);
                    }
                    outputPixelArray[(int)(y*modifiedW+x)]=pixelArray[index];
                }
            }
            BufferedImage modifiedData=new BufferedImage(modifiedW,modifiedH,imgData.getType());
            modifiedData.setRGB(0,0,modifiedW,modifiedH,outputPixelArray,0,modifiedW);
            imgWriter.write(modifiedData);
        }catch (Exception e){
            e.printStackTrace();
        }
    }*/
    public static void ImageProcess_Lanczos(String imgPath,float scale,int LancsozWinSize){
        String format=imgPath.substring(imgPath.length()-3,imgPath.length());
        File img=new File(imgPath);
        File imgModified=new File("Mod-"+scale+"-"+imgPath);
        Iterator readers = ImageIO.getImageReadersByFormatName(format);
        ImageReader imgReader=(ImageReader)readers.next();
        Iterator writers = ImageIO.getImageWritersByFormatName(format);
        ImageWriter imgWriter=(ImageWriter)writers.next();
        LancsozWinSize=LancsozWinSize<=2?2:LancsozWinSize;
        LancsozWinSize=LancsozWinSize>=6?6:LancsozWinSize;
        /*double[] LanczosA1 = new double[] { -0.00623896218505032, -0.0122238956025722, -0.0179556611741633, -0.0234353793884155, -0.028664425422539, -0.0336444239814841, -0.0383772438642046, -0.0428649922670393, -0.0471100088344975, -0.0511148594680326, -0.0548823299036605, -0.0584154190695433, -0.0617173322348938, -0.0647914739617815, -0.0676414408716196, -0.0702710142382982, -0.0726841524200902, -0.0748849831426012, -0.0768777956451566, -0.0786670327031274, -0.0802572825387739, -0.0816532706332581, -0.0828598514525135, -0.0838820000996894, -0.0847248039068906, -0.0853934539789171, -0.0858932367016755, -0.0862295252278804, -0.0864077709525887, -0.0864334949910196, -0.086312279671003, -0.0860497600522689, -0.0856516154846428, -0.0851235612170509, -0.0844713400690516, -0.0837007141764163, -0.0828174568220629, -0.0818273443634177, -0.0807361482670294, -0.0795496272610035, -0.0782735196155422, -0.0769135355615895, -0.0754753498572731, -0.0739645945115212, -0.0723868516738999, -0.0707476466993797, -0.0690524413963838, -0.0673066274661114, -0.0655155201407567, -0.0636843520278618, -0.0618182671676555, -0.0599223153098279, -0.0580014464157926, -0.0560605053920726, -0.0541042270600343, -0.0521372313667693, -0.0501640188415028, -0.048188966301476, -0.0462163228108206, -0.0442502058955092, -0.0422945980170336, -0.0403533433070252, -0.0384301445645995, -0.0365285605177724, -0.0346520033498648, -0.0328037364913793, -0.0309868726774121, -0.0292043722702325, -0.0274590418462525, -0.0257535330461864, -0.0240903416868009, -0.0224718071322479, -0.0209001119225812, -0.0193772816566703, -0.0179051851263444, -0.0164855346982315, -0.015119886939392, -0.013809643482501, -0.0125560521259855, -0.0113602081641975, -0.0102230559423803, -0.00914539063088284, -0.00812786021277406, -0.00717096767873418, -0.00627507342282205, -0.00544039783246632, -0.00466702406578012, -0.00395490100907222, -0.00330384640720963, -0.00271355015928674, -0.00218357777186753, -0.00171337396189679, -0.00130226640121749, -0.000949469594490465, -0.00065408888218426, -0.000415124560192089, -0.000231476107535702, -0.000101946513534946, -0 };
        double[] LanczosA2 = new double[] { 0.999794398630316, 0.999177779156011, 0.998150695261436, 0.996714069021198, 0.994869189802256, 0.992617712728975, 0.989961656713271, 0.986903402052547, 0.983445687598761, 0.979591607502511, 0.975344607536654, 0.9707084810045, 0.965687364238256, 0.960285731693901, 0.954508390649264, 0.948360475512591, 0.941847441749449, 0.934975059436304, 0.927749406449645, 0.920176861299994, 0.912264095620641, 0.904018066321406, 0.895446007418168, 0.886555421549337, 0.877354071190877, 0.867849969581877, 0.858051371373022, 0.847966763010743, 0.83760485287009, 0.826974561149762, 0.816085009542993, 0.804945510698284, 0.793565557484247, 0.781954812073053, 0.770123094857198, 0.758080373214511, 0.745836750136481, 0.733402452735159, 0.720787820644003, 0.708003294328147, 0.695059403319663, 0.68196675439345, 0.668736019699406, 0.655377924866579, 0.641903237094975, 0.628322753250659, 0.614647287979759, 0.600887661856885, 0.587054689583387, 0.573159168250756, 0.559211865684328, 0.545223508882287, 0.531204772564777, 0.517166267847729, 0.503118531055783, 0.489072012688425, 0.47503706655321, 0.461023939079635, 0.447042758826945, 0.433103526198797, 0.419216103377392, 0.405390204489315, 0.391635386014941, 0.37796103745288, 0.364376372250524, 0.350890419011333, 0.33751201298905, 0.324249787878619, 0.311112167913061, 0.298107360275149, 0.285243347832182, 0.272527882201696, 0.259968477155437, 0.247572402368387, 0.235346677519141, 0.223298066747373, 0.211433073473617, 0.199757935586031, 0.188278620998268, 0.177000823582037, 0.165929959477376, 0.155071163783102, 0.144429287629353, 0.13400889563358, 0.123814263740785, 0.113849377448258, 0.104117930414501, 0.0946233234514916, 0.0853686638988765, 0.0763567653781721, 0.0675901479244855, 0.059071038492763, 0.050801371835042, 0.0427827917446759, 0.0350166526629909, 0.0275040216433488, 0.0202456806670952, 0.0132421293054104, 0.00649358772061002 };
        double[] LanczosA3 = new double[] { 0.00649358772061002, 0.0132421293054104, 0.0202456806670952, 0.0275040216433488, 0.0350166526629909, 0.0427827917446759, 0.0508013718350421, 0.059071038492763, 0.0675901479244855, 0.0763567653781721, 0.0853686638988765, 0.0946233234514916, 0.104117930414501, 0.113849377448258, 0.123814263740785, 0.13400889563358, 0.144429287629353, 0.155071163783102, 0.165929959477376, 0.177000823582037, 0.188278620998268, 0.199757935586031, 0.211433073473617, 0.223298066747373, 0.235346677519141, 0.247572402368387, 0.259968477155437, 0.272527882201696, 0.285243347832182, 0.298107360275149, 0.311112167913061, 0.324249787878619, 0.33751201298905, 0.350890419011333, 0.364376372250524, 0.37796103745288, 0.391635386014941, 0.405390204489315, 0.419216103377392, 0.433103526198797, 0.447042758826944, 0.461023939079634, 0.475037066553209, 0.489072012688425, 0.503118531055783, 0.517166267847729, 0.531204772564777, 0.545223508882287, 0.559211865684328, 0.573159168250756, 0.587054689583387, 0.600887661856885, 0.614647287979759, 0.628322753250659, 0.641903237094975, 0.655377924866579, 0.668736019699406, 0.68196675439345, 0.695059403319663, 0.708003294328147, 0.720787820644003, 0.733402452735159, 0.745836750136481, 0.758080373214511, 0.770123094857198, 0.781954812073053, 0.793565557484247, 0.804945510698284, 0.816085009542993, 0.826974561149762, 0.837604852870089, 0.847966763010743, 0.858051371373022, 0.867849969581877, 0.877354071190877, 0.886555421549337, 0.895446007418168, 0.904018066321406, 0.912264095620641, 0.920176861299994, 0.927749406449646, 0.934975059436304, 0.941847441749449, 0.948360475512591, 0.954508390649264, 0.960285731693901, 0.965687364238256, 0.9707084810045, 0.975344607536654, 0.979591607502512, 0.983445687598761, 0.986903402052547, 0.989961656713271, 0.992617712728975, 0.994869189802256, 0.996714069021198, 0.998150695261436, 0.999177779156011, 0.999794398630316 };
        double[] LanczosA4 = new double[] { -0, -0.000101946513534946, -0.000231476107535702, -0.000415124560192089, -0.00065408888218426, -0.000949469594490465, -0.0013022664012175, -0.00171337396189679, -0.00218357777186754, -0.00271355015928674, -0.00330384640720965, -0.00395490100907222, -0.00466702406578012, -0.00544039783246632, -0.00627507342282205, -0.00717096767873415, -0.00812786021277406, -0.00914539063088281, -0.0102230559423803, -0.0113602081641975, -0.0125560521259855, -0.013809643482501, -0.015119886939392, -0.0164855346982315, -0.0179051851263444, -0.0193772816566703, -0.0209001119225812, -0.0224718071322479, -0.0240903416868009, -0.0257535330461864, -0.0274590418462525, -0.0292043722702326, -0.0309868726774121, -0.0328037364913794, -0.0346520033498648, -0.0365285605177724, -0.0384301445645995, -0.0403533433070252, -0.0422945980170336, -0.0442502058955092, -0.0462163228108205, -0.048188966301476, -0.0501640188415028, -0.0521372313667693, -0.0541042270600343, -0.0560605053920726, -0.0580014464157926, -0.0599223153098279, -0.0618182671676555, -0.0636843520278618, -0.0655155201407567, -0.0673066274661114, -0.0690524413963838, -0.0707476466993797, -0.0723868516738999, -0.0739645945115212, -0.0754753498572731, -0.0769135355615895, -0.0782735196155421, -0.0795496272610035, -0.0807361482670294, -0.0818273443634177, -0.0828174568220629, -0.0837007141764163, -0.0844713400690516, -0.0851235612170509, -0.0856516154846428, -0.0860497600522689, -0.086312279671003, -0.0864334949910196, -0.0864077709525887, -0.0862295252278804, -0.0858932367016755, -0.0853934539789171, -0.0847248039068906, -0.0838820000996894, -0.0828598514525135, -0.0816532706332581, -0.0802572825387739, -0.0786670327031274, -0.0768777956451566, -0.0748849831426012, -0.0726841524200902, -0.0702710142382982, -0.0676414408716196, -0.0647914739617815, -0.0617173322348938, -0.0584154190695433, -0.0548823299036604, -0.0511148594680326, -0.0471100088344975, -0.0428649922670393, -0.0383772438642045, -0.0336444239814841, -0.028664425422539, -0.0234353793884155, -0.0179556611741633, -0.0122238956025722, -0.00623896218505032 };
        */
        try {
            if (!imgModified.exists()) {
                imgModified.createNewFile();
            }
            ImageInputStream imgIStream = ImageIO.createImageInputStream(img);
            imgReader.setInput(imgIStream);
            ImageOutputStream imgOStream = ImageIO.createImageOutputStream(imgModified);
            imgWriter.setOutput(imgOStream);
            BufferedImage imgData = imgReader.read(0);
            int originW = imgData.getWidth();
            int originH = imgData.getHeight();
            int modifiedW = Math.round(originW * scale);
            int modifiedH = Math.round(originH * scale);
            int x = 0, y = 0,p0 = 0, p1 = 0, p2 = 0, p3 = 0, p4 = 0, gray = 0;
            double[] sampleWeigh=new double[4];
            int[] pixelArray=new int[imgData.getHeight()*imgData.getWidth()];
            int[] modifiedPixelArray=new int[modifiedW*modifiedH];
            pixelArray=imgData.getRGB(0,0,originW,originH,pixelArray,0,originW);
            ColorModel color=ColorModel.getRGBdefault();
            for(int mY=0;mY<modifiedH;mY++){
                double originRow=(double)mY/(double)scale;
                int intORow=((int)originRow)>=originH?originH-1:(int)originRow;
                double deciORow=Math.abs(originRow-intORow);
                for(int mX=0;mX<modifiedW;mX++){
                    double originCol=(double)mX/(double)scale;
                    int intOCol=((int)originCol)>=originW?originW-1:(int)originCol;
                    double deciOCol=Math.abs(originCol-intOCol);
                    int[] rgba=new int[4];
                    //if(deciOCol!=0){
                    /*int weigh=(int)(deciOCol*100.0)-2;
                    weigh=(weigh<0?0:weigh);
                    weigh=(weigh>=98?98:weigh);
                    sampleWeigh[0]=LanczosA1[weigh];
                    sampleWeigh[1]=LanczosA2[weigh];
                    sampleWeigh[2]=LanczosA3[weigh];
                    sampleWeigh[3]=1-sampleWeigh[0]-sampleWeigh[1]-sampleWeigh[2];*/
                    int weigh=0;
                    for(int oY=-LancsozWinSize+1;oY<=LancsozWinSize;oY++){
                        int position=intORow*originW+intOCol;
                        position=(position>=(originH-LancsozWinSize-1)*originW?(originH-LancsozWinSize-1)*originW:position);
                        position=(position<=LancsozWinSize*modifiedW?LancsozWinSize*modifiedW+intOCol:position);
                        for(int oX=-LancsozWinSize+1;oX<=LancsozWinSize;oX++){
                            weigh+=getWeigh(LancsozWinSize,oX);
                            rgba[0]+=(int)((double)(color.getRed(pixelArray[position+oX]))*getWeigh(LancsozWinSize,oX));
                            rgba[1]+=(int)((double)color.getGreen(pixelArray[position+oX])*getWeigh(LancsozWinSize,oX));
                            rgba[2]+=(int)((double)color.getBlue(pixelArray[position+oX])*getWeigh(LancsozWinSize,oX));
                            rgba[3]+=(int)((double)color.getAlpha(pixelArray[position+oX])*getWeigh(LancsozWinSize,oX));
                        }
                    }
                    rgba[0]=clamp(rgba[0]/weigh);
                    rgba[1]=clamp(rgba[1]/weigh);
                    rgba[2]=clamp(rgba[2]/weigh);
                    rgba[3]=clamp(rgba[3]/weigh);
                    modifiedPixelArray[mY*modifiedW+mX]=rgba[3]<<24|rgba[0]<<16|rgba[1]<<8|rgba[2];
                }
            }
            BufferedImage modifiedData=new BufferedImage(modifiedW,modifiedH,imgData.getType());
            modifiedData.setRGB(0,0,modifiedW,modifiedH,modifiedPixelArray,0,modifiedW);
            imgWriter.write(modifiedData);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static double getWeigh(int a ,int x){
        if(x==0){
            return 1d;
        }
        else if(-a<x||x>a){
            return a*Math.sin(Math.PI*x)*Math.sin(Math.PI*x/a)/Math.pow(Math.PI*x,2);
        }
        else{
            return 0;
        }
    }
    public static int clamp(int a){
        a=a<=0?0:a;
        a=a>=255?255:a;
        return a;
    }

    /*using bicubic interpolation
    public static void enlargeImg(String imgPath,float scaleX,float scaleY){
        String format=imgPath.substring(imgPath.length()-3,imgPath.length());
        File img=new File(imgPath);
        File imgModified=new File("Mod-3-"+imgPath);
        Iterator readers = ImageIO.getImageReadersByFormatName(format);
        ImageReader imgReader=(ImageReader)readers.next();
        Iterator writers = ImageIO.getImageWritersByFormatName(format);
        ImageWriter imgWriter=(ImageWriter)writers.next();
        try {
            if (scaleX < 1 || scaleY < 1) {
                throw new RuntimeException("Invalid Scale Input");
            }
            if (!imgModified.exists()) {
                imgModified.createNewFile();
            }
            ImageInputStream imgIStream = ImageIO.createImageInputStream(img);
            imgReader.setInput(imgIStream);
            ImageOutputStream imgOStream = ImageIO.createImageOutputStream(imgModified);
            imgWriter.setOutput(imgOStream);
            BufferedImage imgData = imgReader.read(0);
            int originW=imgData.getWidth();
            int originH=imgData.getHeight();
            int modifiedW=Math.round(originW*scaleX);
            int modifiedH=Math.round(originH*scaleY);
            int[] pixelArray=new int[imgData.getHeight()*imgData.getWidth()];
            int[] modifiedPixelArray=new int[modifiedH*modifiedW];
            pixelArray=imgData.getRGB(0,0,originW,originH,pixelArray,0,originW);
            for(int mY=0;mY<modifiedH;mY++){
                double intRow=Math.floor((float) mY*scaleY);
                double deciRow=(float) mY*scaleY-intRow;
                ColorModel color=ColorModel.getRGBdefault();
                for(int mX=0;mX<modifiedW;mX++){
                    double intCol=Math.floor((float)mX*scaleX);
                    double deciCol=(float) mY*scaleY-intRow;
                    double[] argb_d={0,0,0,0};
                    double weighSum=0.0d;
                    for(int sampleY=-1;sampleY<3;sampleY++){
                        for(int sampleX=-1;sampleX<3;sampleX++){
                            double sample1=0d;
                            double sample2=0d;
                            double weigh;
                            sample1=((double) sampleY-deciRow)/2.0d>0.0d ? 1.0d-((double) sampleY-deciRow):((double) sampleY-deciRow)+1.0d;
                            sample2=(-((double)sampleX)-deciCol)/2.0d>0.0d ? 1.0d+((double)sampleX)-deciCol:1.0d-((double)sampleX)-deciCol;
                            weigh=sample1*sample2;
                            weighSum+=weigh;
                            int position=((int)intRow+sampleY>originH?originH:((int)intRow+sampleY)<0d?0:((int)intRow+sampleY))*originW+
                                    ((int)intCol+sampleX>originW?originW:((int)intCol+sampleX)<0d?0:((int)intCol+sampleX));
                            if(position>=originH*originW-1){
                                position=originH*originW-1;
                            }
                            argb_d[0]+=((pixelArray[position]>>24&0xff)*weigh);
                            argb_d[1]+=((pixelArray[position]>>16&0xff)*weigh);
                            argb_d[2]+=((pixelArray[position]>>8&0xff)*weigh);
                            argb_d[3]+=((pixelArray[position]&0xff)*weigh);
                        }
                    }
                    int[] argb={0,0,0,0};
                    for(int i=0;i<4;i++){
                        argb_d[i]/=weighSum;
                        argb[i]=(((int)argb_d[i])>255?255:((int)argb_d[i])<<((3-i)*8));
                    }
                    modifiedPixelArray[mY*modifiedH+mX]=argb[0]|argb[1]|argb[2]|argb[3];
                }
            }
            BufferedImage modifiedData=new BufferedImage(modifiedW,modifiedH,imgData.getType());
            modifiedData.setRGB(0,0,modifiedW,modifiedH,modifiedPixelArray,0,modifiedW);
            imgWriter.write(modifiedData);
        }catch (Exception e){
            e.printStackTrace();
        }
    }*/

}
